package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DeviceBindingInfo;
import com.ruoyi.system.service.IDeviceBindingInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备绑定Controller
 * //20250214 云计算-智能车联-04-数据统计
 * @author 刘进祥
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/system/binding")
public class DeviceBindingInfoController extends BaseController
{
    @Autowired
    private IDeviceBindingInfoService deviceBindingInfoService;

    /**
     * 查询设备绑定列表
     */
    @PreAuthorize("@ss.hasPermi('system:binding:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceBindingInfo deviceBindingInfo)
    {
        startPage();
        List<DeviceBindingInfo> list = deviceBindingInfoService.selectDeviceBindingInfoList(deviceBindingInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备绑定列表
     */
    @PreAuthorize("@ss.hasPermi('system:binding:export')")
    @Log(title = "设备绑定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceBindingInfo deviceBindingInfo)
    {
        List<DeviceBindingInfo> list = deviceBindingInfoService.selectDeviceBindingInfoList(deviceBindingInfo);
        ExcelUtil<DeviceBindingInfo> util = new ExcelUtil<DeviceBindingInfo>(DeviceBindingInfo.class);
        util.exportExcel(response, list, "设备绑定数据");
    }

    /**
     * 获取设备绑定详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:binding:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceBindingInfoService.selectDeviceBindingInfoById(id));
    }

    /**
     * 新增设备绑定
     */
    @PreAuthorize("@ss.hasPermi('system:binding:add')")
    @Log(title = "设备绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceBindingInfo deviceBindingInfo)
    {
        return toAjax(deviceBindingInfoService.insertDeviceBindingInfo(deviceBindingInfo));
    }

    /**
     * 修改设备绑定
     */
    @PreAuthorize("@ss.hasPermi('system:binding:edit')")
    @Log(title = "设备绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceBindingInfo deviceBindingInfo)
    {
        return toAjax(deviceBindingInfoService.updateDeviceBindingInfo(deviceBindingInfo));
    }

    /**
     * 删除设备绑定
     */
    @PreAuthorize("@ss.hasPermi('system:binding:remove')")
    @Log(title = "设备绑定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceBindingInfoService.deleteDeviceBindingInfoByIds(ids));
    }
}
